import pymysql
import pandas as pd
# 建立连接
conn = pymysql.connect(
    user='root',
    password='1234',
    host='localhost',
    database='db1',
    port=3306,
    charset='utf8mb4',
)

df = pd.read_sql('SELECT * FROM db1.tb_data', con=conn, parse_dates=True)

df.to_csv('data/data.csv', index=False)